package org.applet.game.app.rpg.widgets;

import java.awt.Event;
import java.awt.image.BufferedImage;
import org.applet.game.app.rpg.resource.MagicResource;
import org.applet.game.app.rpg.scene.JXScene;
import org.applet.game.framework.component.FrameButton;
import org.applet.game.framework.core.Container;

public class MagicSelector extends Container {

	BufferedImage[] imageSource;
	public MagicSelector()
	{
		imageSource = MagicResource.getMagicTitles();
		final FrameButton[] magics = new FrameButton[15];
		final MagicSelector selector = this;
		for(int i=0;i<magics.length;i++)
		{
			int offsetY = i/6;
			int offX = i%6;
			final int magicIndex = i;
			magics[i] = new FrameButton(imageSource[i], 0, 0, 27, 27){
				@Override
				public boolean mouseDown(Event e) {
					selector.setVisible(false);
					((JXScene)scene).selectMagic(magicIndex);
					return false;
				}
			};
			final FrameButton button = magics[i];
			//button.setVisible(false);
			button.setLocation(27*offX, offsetY*28);
			button.setAlpha(0.8f);
			button.setName(""+i);
			add(button);
		}
	}
}
